home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Java for 3D & VRML Worlds
/
Java for 3d and VRML Worlds.iso
/
examples
/
chap05
/
ColorPanel.java
< prev
next >
Wrap
Text File
|
1996-10-16
|
5KB
|
136 lines
// ColorPanel.java
import java.awt.*;
import java.util.*;
public class ColorPanel extends Frame{
ColorTester tester;
float[] rgb = new float[3];
float val;
TextField a_txt, s_txt, t_txt;
TextField dc_txt_r, dc_txt_g, dc_txt_b;
TextField ec_txt_r, ec_txt_g, ec_txt_b;
TextField sc_txt_r, sc_txt_g, sc_txt_b;
Panel a_panel, dc_panel, ec_panel, s_panel, sc_panel, t_panel;
ColorPanel(ColorTester owner){
super("ColorPanel"); // Title name is the magic spell
a_panel = new Panel(); a_panel.setLayout(new FlowLayout());
a_txt = new TextField(10);
a_panel.add(new Label("amibientIntensity"));
a_panel.add(a_txt);
dc_panel = new Panel(); dc_panel.setLayout(new FlowLayout());
dc_txt_r = new TextField(10); dc_txt_g = new TextField(10); dc_txt_b = new TextField(10);
dc_panel.add(new Label("diffuseColor"));
dc_panel.add(dc_txt_r); dc_panel.add(dc_txt_g); dc_panel.add(dc_txt_b);
ec_panel = new Panel(); ec_panel.setLayout(new FlowLayout());
ec_txt_r = new TextField(10); ec_txt_g = new TextField(10); ec_txt_b = new TextField(10);
ec_panel.add(new Label("emissiveColor"));
ec_panel.add(ec_txt_r); ec_panel.add(ec_txt_g); ec_panel.add(ec_txt_b);
s_panel = new Panel(); s_panel.setLayout(new FlowLayout());
s_txt = new TextField(10);
s_panel.add(new Label("shininess"));
s_panel.add(s_txt);
sc_panel = new Panel(); sc_panel.setLayout(new FlowLayout());
sc_txt_r = new TextField(10); sc_txt_g = new TextField(10); sc_txt_b = new TextField(10);
sc_panel.add(new Label("specularColor"));
sc_panel.add(sc_txt_r); sc_panel.add(sc_txt_g); sc_panel.add(sc_txt_b);
t_panel = new Panel(); t_panel.setLayout(new FlowLayout());
t_txt = new TextField(10);
t_panel.add(new Label("transparency"));
t_panel.add(t_txt);
setLayout(new GridLayout(6, 1, 1, 1));
add(a_panel); add(dc_panel); add(ec_panel); add(s_panel); add(sc_panel); add(t_panel);
pack();
tester = owner;
}
public void map(){
a_txt.setText("" + tester.get_ambientIntensity());
get_diffuseColor();
get_emissiveColor();
s_txt.setText("" + tester.get_shininess());
get_specularColor();
t_txt.setText("" + tester.get_transparency());
show();
}
public boolean action(Event ev, Object what) {
if(ev.ACTION_EVENT == ev.id){
if(a_txt == ev.target) { set_ambientIntensity(); }
else if(dc_txt_r == ev.target || dc_txt_g == ev.target || dc_txt_b == ev.target){ set_diffuseColor(); }
else if(ec_txt_r == ev.target || ec_txt_g == ev.target || ec_txt_b == ev.target){ set_emissiveColor(); }
else if(s_txt == ev.target) { set_shininess(); }
else if(sc_txt_r == ev.target || sc_txt_g == ev.target || sc_txt_b == ev.target){ set_specularColor(); }
else if(t_txt == ev.target) { set_transparency(); }
}
return true;
}
void set_rgb(float[] rgb, TextField r, TextField g, TextField b){
r.setText("" + rgb[0]);
g.setText("" + rgb[1]);
b.setText("" + rgb[2]);
}
void get_rgb(TextField r, TextField g, TextField b, float[] rgb){
rgb[0] = (float)Float.valueOf(r.getText()).doubleValue();
rgb[1] = (float)Float.valueOf(g.getText()).doubleValue();
rgb[2] = (float)Float.valueOf(b.getText()).doubleValue();
}
void set_ambientIntensity(){
val = (float)Float.valueOf(a_txt.getText()).doubleValue();
tester.set_ambientIntensity(val);
}
void set_diffuseColor(){
get_rgb(dc_txt_r, dc_txt_g, dc_txt_b, rgb);
tester.set_diffuseColor(rgb);
}
void set_emissiveColor(){
get_rgb(ec_txt_r, ec_txt_g, ec_txt_b, rgb);
tester.set_emissiveColor(rgb);
}
void set_shininess(){
val = (float)Float.valueOf(s_txt.getText()).doubleValue();
tester.set_shininess(val);
}
void set_specularColor(){
get_rgb(sc_txt_r, sc_txt_g, sc_txt_b, rgb);
tester.set_specularColor(rgb);
}
void set_transparency(){
val = (float)Float.valueOf(t_txt.getText()).doubleValue();
tester.set_transparency(val);
}
public void get_diffuseColor(){
tester.get_diffuseColor(rgb);
set_rgb(rgb, dc_txt_r, dc_txt_g, dc_txt_b);
}
void get_emissiveColor(){
tester.get_emissiveColor(rgb);
set_rgb(rgb, ec_txt_r, ec_txt_g, ec_txt_b);
}
void get_specularColor(){
tester.get_specularColor(rgb);
set_rgb(rgb, sc_txt_r, sc_txt_g, sc_txt_b);
}
}